package m07;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * This class controls the Goods. It constructs the Goods and
 * places the constructed Goods into an ArrayList.
 * 
 * @author Jessica Roberts
 * @version 1.2 19 October 2012
 */

public class Good implements Serializable {
	private String name;
	/** The min tech level to produce this resource */
	private int minTechProduce;
	/** The min tech level to use this resource */
	private int minTechUse;
	/** The base price for the unit */
	private int basePrice;
	private int incPerLevel;
	/** The maximum percentage that the price can vary above or below base */
	private int var; //
	/** If this condition present, the resource price is low */
	private String CR;
	/** If this condition is present, the resource price is high */
	private String ER;
	/** Min price with a space trade with a random player(not SS) */
	private double minPrice;
	/** Max price with a space trade with a random player(not SS) */
	private double maxPrice;
	private int currentPrice;

	/** The ArrayList that contains the created Solar Systems */
	private static ArrayList<Good> goods = new ArrayList<Good>();


	/**
	 * This constructor takes in the parameters for the Good and sets 
	 * them equal to the instantiated variables.
	 * 
	 * @param name This is the name of the Good
	 * @param MTLP The min tech level to produce this resource
	 * @param MTLU The min tech level to use this resource
	 * @param basePrice The base price for the unit
	 * @param IPL The price increase per tech level
	 * @param var The maximum percentage that the price can vary above or below base
	 * @param CR The condition necessary for the price to be high
	 * @param ER The condition necessary for the price to be low
	 * @param minPrice Min price with a space trade with a random player(not SS)
	 * @param maxPrice Max price with a space trade with a random player(not SS)
	 */
	public Good (String name, int MTLP, int MTLU, int basePrice, int IPL, int var,
			String CR, String ER, double minP, double maxP, int currentPrice)
	{
		this.name = name;
		this.minTechProduce = MTLP;
		this.minTechUse = MTLU;
		this.basePrice = basePrice;
		this.incPerLevel = IPL;
		this.var = var;
		this.CR = CR;
		this.ER = ER;
		this.minPrice = minP;
		this.maxPrice = maxP;
		this.currentPrice = currentPrice;
	} // end Constructor

	/**
	 * This method creates the hard-coded Goods, adds them to the 
	 * ArrayList, and prints the ArrayList.
	 */
	public void activateGoods() {
		Good gwater, gfurs, gfood, gore, ggames, gfire, gmeds, gmachine, gnarc, grobot;
		gwater = new Good ("Water", 0, 0, 30, 3, 4, "LOTSOFWATER", "DESERT", 30, 50, 0);
		gfurs = new Good ("Furs", 0, 0, 250, 10, 10, "RICHFAUA", "LIFELESS", 230, 280, 0);
		gfood = new Good ("Food", 1, 0, 100, 5, 5, "RICHSOIL", "POORSOIL", 90, 160, 0);
		gore = new Good ("Ore", 2, 2, 350, 20, 10, "MINERALRICH", "MINERALPOOR", 350, 420, 0);
		ggames = new Good ("Games", 3, 1, 250, -10, 5, "ARTISTIC", null, 160, 270, 0);
		gfire = new Good ("Firearms", 3, 1, 1250, -75, 100, "WARLIKE", null, 600, 1100, 0);
		gmeds = new Good ("Medicine", 4, 1, 650, -20, 10, "LOTSOFHERBS", null, 400, 700, 0);
		gmachine = new Good ("Machines", 4, 3, 900, -30, 5, null, null, 600, 800, 0);
		gnarc = new Good ("Narcotics", 5, 0, 3500, -125, 150, "WEIRDMUSHROOMS", null, 2000, 3000, 0);
		grobot = new Good ("Robots", 6, 4, 5000, -150, 100, null, null, 3500, 5000, 0);

		// Adding the Good objects to the ArrayList
		goods.add(gwater);
		goods.add(gfurs);
		goods.add(gfood);
		goods.add(gore);
		goods.add(ggames);
		goods.add(gfire);
		goods.add(gmeds);
		goods.add(gmachine);
		goods.add(gnarc);
		goods.add(grobot);
	} // end method activateGoods


	/**
	 * This method returns the name of the Good.
	 * 
	 * @return The name of the Good.
	 */
	public String getName()
	{
		return name;
	} // end method getName

	/**
	 * This method returns the min tech level to produce this resource.
	 * 
	 * @return The min tech level to produce this resource.
	 */
	public int getMinTechProduce()
	{
		return minTechProduce;
	} // end method getMinTechProduce

	/**
	 * This method returns the min tech level to use this resource.
	 * 
	 * @return The min tech level to use this resource.
	 */
	public int getMinTechUse()
	{
		return minTechUse;
	} // end method getMinTechUse

	/**
	 * This method returns the base price for one unit.
	 * 
	 * @return The base price.
	 */
	public int getBasePrice()
	{
		return basePrice;
	} // end method getBasePrice

	/**
	 * This method returns the price increase per tech level.
	 * 
	 * @return The price increace per tech level.
	 */
	public int getIncPerLevel()
	{
		return incPerLevel;
	} // end method getIncPerLevel

	/**
	 * This method returns the maximum percentage that the price can vary above or below base.
	 * 
	 * @return The maximum percentage that the price can vary above or below base.
	 */
	public int getVar()
	{
		return var;
	} // end method getVar

	/**
	 * This method returns the condition for the price to be low.
	 * 
	 * @return The the condition necessary for the price to be low.
	 */
	public String getCR()
	{
		return CR;
	} // end method getCR

	/**
	 * This method returns the condition necessary for the price to be high.
	 * 
	 * @return The condition necessary for the price to be high.
	 */
	public String getER()
	{
		return ER;
	} // end method getER

	/**
	 * This method returns the minimum price with a trade with a random player.
	 * 
	 * @return The the minimum price with a trade with a random player.
	 */
	public double getMinPrice()
	{
		return minPrice;
	} // end method getMinPrice

	/**
	 * This method returns the maximum price with a trade with a random player.
	 * 
	 * @return The maximum price with a trade with a random player.
	 */
	public double getMaxPrice()
	{
		return maxPrice;
	} // end method getMaxPrice

	public int getCurrentPrice()
	{
		return currentPrice;
	}

	public void updatePrice(int techLevel) 
	{
		currentPrice = basePrice + (incPerLevel * (techLevel - minTechProduce)) + var;
	}

} // end class Good
